package com.weishi.common.redisson;


import com.weishi.common.utils.ConfigUtil;
import com.weishi.common.utils.LoggerUtils;
import org.redisson.Redisson;
import org.redisson.config.Config;

public class RedissonManager {

    private static Config config = new Config();

    private static Redisson redisson = null;

    public static Redisson getRedissonInstance() {
        if(redisson == null){
            synchronized (RedissonManager.class){
                if(redisson == null){
                    init();
                }
            }
        }
        return redisson;
    }

    private static String redisIp = ConfigUtil.getValue("redis.ip");
    private static Integer redisPort = Integer.parseInt(ConfigUtil.getValue("redis.port"));
    private static String redisPassword = ConfigUtil.getValue("redis.password");

    private static void init(){
        try {
            config.useSingleServer().setAddress("redis://"+redisIp+":"+redisPort).setPassword(redisPassword);
            redisson = (Redisson) Redisson.create(config);

        } catch (Exception e) {
            LoggerUtils.getLogger().error("redisson init error",e);
        }
    }
}
